//
//  DVImagePickerNavigationController.m
//  ImagePicker
//
//  Created by csh on 16/4/13.
//  Copyright © 2016年 com.read. All rights reserved.
//
#import "DVImagePickerManager.h"
#import "DVImagePickerController.h"
#import "DVImagePickerNavigationController.h"

@implementation DVImagePickerNavigationController
- (instancetype)initWithArray:(NSMutableArray *)array
{
    self  = [super init];
    if(self)
    {
        _array = array;
        [self initNavigationBar];
        [self pushPhotoViewController];
    }
    return self;
}

#pragma - mark pushViewController
- (void)pushPhotoViewController
{
    [[DVImagePickerManager manager] getAlbumWithCompletion:^(DVAlbumModel *model) {
        DVImagePickerController *imagePicker = [[DVImagePickerController alloc]init];
        imagePicker.model = model;
        imagePicker.selectPhotoArray = self.array;
        [self pushViewController:imagePicker animated:YES];
    }];
}


- (void)initNavigationBar
{
    NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                               [UIColor whiteColor],NSForegroundColorAttributeName, [UIFont boldSystemFontOfSize:17.0f], NSFontAttributeName, nil];
    self.navigationBar.titleTextAttributes = navbarTitleTextAttributes;
    self.edgesForExtendedLayout = UIRectEdgeTop;
    UIImage *image  = [UIImage imageNamed:@"navigation_back"];
    [self.navigationBar setBackgroundImage:[image stretchableImageWithLeftCapWidth:image.size.width/2 topCapHeight:image.size.height/2] forBarMetrics:UIBarMetricsDefault];
    self.navigationBar.translucent = NO;
}
@end

@implementation LeftButton
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat titleX = 15;
    CGFloat titleY = 0;
    CGFloat titleW = contentRect.size.width-30;
    CGFloat titleH = contentRect.size.height;
    return CGRectMake(titleX, titleY, titleW, titleH);
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat imageX = -10;
    CGFloat imageY = (contentRect.size.height-30)/2;
    CGFloat imageW = 30;
    CGFloat imageH = 30;
    return CGRectMake(imageX, imageY, imageW, imageH);
}
@end
